import java.util.Scanner;
import java.util.Stack;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2025-07-20
 * Time: 15:03
 */
public class Test74 {

    public static int largestRectangleArea(int[] heights) {
        // 首尾加0
        int n = heights.length;
        int[] num = new int[n+2];
        for(int i = 1; i < n; i++){
            num[i] = heights[i-1];
        }
        heights = num;
        Stack<Integer> st = new Stack<>();
        st.push(0);
        int ret = 0;
        for(int i = 0; i < n+2;i++) {
            while(!st.isEmpty() && heights[st.peek()] > heights[i]) {
                int mid  = st.peek();
                st.pop();
                int left = st.peek();
                int right = i;
                ret = Math.max(ret,(right-left-1)*heights[mid]);
            }
            st.push(i);
        }
        return ret;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] heights = new int[n];
        for(int i = 0; i < n; i++) {
            heights[i] = sc.nextInt();
        }
        int ret = largestRectangleArea(heights);
        System.out.println(ret);
    }
}
